package com.example.simplenet;

import java.util.ArrayList;

import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;

public class Notifier {

	private static long[] mPattern = { 0, 200, 500, 200 };
	
	public static void attackNotify(Context context) {
	
		Intent intent = new Intent(context, MainActivity.class);
		intent.setAction("android.intent.action.MAIN");
		intent.addCategory("android.intent.category.LAUNCHER");
		PendingIntent pIntent = PendingIntent.getActivity(context, 1, intent , PendingIntent.FLAG_UPDATE_CURRENT);
		NotificationCompat.Builder builder = new Builder(context)
			.setAutoCancel(true)
			.setContentTitle(context.getString(R.string.you_are_under_attack))
			.setContentText("")
			.setSmallIcon(R.drawable.ic_attack)
			.setContentIntent(pIntent)
			.setVibrate(mPattern)
			.setSound(Uri.parse("android.resource://com.example.simplenet/raw/attack"));
		
		NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		manager.notify(ConnectionMan.ATTACK_NOTIFICATION_ID, builder.build());
	}
	
	public static void abandonedNotify(Context context, ArrayList<AbandonedInfo> found) {

		Intent intent = new Intent(context, MainActivity.class);
		intent.setAction("android.intent.action.MAIN");
		intent.addCategory("android.intent.category.LAUNCHER");
		PendingIntent pIntent = PendingIntent.getActivity(context, 1, intent , PendingIntent.FLAG_UPDATE_CURRENT);
		String text;
		if (found.size() == 1)
			text = context.getString(R.string.found_one_abandoned, found.get(0).getName(), found.get(0).getDistance(), found.get(0).getPoints());
		else
			text = context.getString(R.string.found_n_abandoned, found.size());
 		NotificationCompat.Builder builder = new Builder(context)
			.setAutoCancel(true)
			.setContentTitle(context.getString(R.string.new_abandoned))
			.setContentText(text)
			.setSmallIcon(R.drawable.ic_abandoned)
			.setContentIntent(pIntent)
			.setVibrate(mPattern)
			.setSound(Uri.parse("android.resource://com.example.simplenet/raw/abandoned"));
		
		NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
		manager.notify(ConnectionMan.ABANDONED_NOTIFICATION_ID, builder.build());
	}
	
}
